#ifndef GRAPHCONTROLWIDGET_H
#define GRAPHCONTROLWIDGET_H

#include <QDockWidget>
#include <QPushButton>
#include <QGraphicsScene>
#include <QMenu>
#include <QAction>
#include <QMenuBar>

#include <QtTreePropertyBrowser>
#include <QtVariantPropertyManager>

#include <graph.h>
#include <graphgui.h>

class GraphPropertyItem
{
public:
	enum Type { VertexType, EdgeUType, EdgeVType, EdgeLengthType };
	virtual Type type() const = 0;
};

class GraphVertexPropertyItem : public GraphPropertyItem
{
public:
	Type type() const { return VertexType; }
	Vertex vertex;
};

class GraphEdgePropertyItem : public GraphPropertyItem
{
public:
	Edge edge;
};

class GraphEdgeUPropertyItem : public GraphEdgePropertyItem
{
public:
	Type type() const { return EdgeUType; }
};

class GraphEdgeVPropertyItem : public GraphEdgePropertyItem
{
public:
	Type type() const { return EdgeVType; }
};

class GraphEdgeLengthPropertyItem : public GraphEdgePropertyItem
{
public:
	Type type() const { return EdgeLengthType; }
};

class GraphControlWidget : public QDockWidget
{
	Q_OBJECT
public:
	GraphControlWidget(QWidget *parent = 0);
private slots:
	void drawGraphClicked();
	void createGraph();
	void addVertex();
	void addEdge();
	void colorSomeEdges();
private:
	void prepareBrowser();
private slots:
	void propertyValueChanged(QtProperty *prop, const QVariant &value);
signals:
	void newGraph(QGraphicsScene *);
private:
	QMenu *m_graphMenu;
	QMenuBar *m_menuBar;
	QAction *m_vertexAction;
	QAction *m_edgeAction;
	QAction *m_graphAction;
	QAction *m_drawAction;
	QAction *m_colorEdges;

	QtTreePropertyBrowser *m_browser;
	QtVariantPropertyManager *m_manager;
	QtVariantEditorFactory *m_factory;

	QMap<QtProperty *, GraphPropertyItem *> m_propToItem;

	Graph *m_graph;
	GraphGui *m_graphScene;
};

#endif // GRAPHCONTROLWIDGET_H
